package com.itasura.redis.repository;

import com.itasura.redis.entity.Teacher;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.JpaRepository;

/**
 * @author sailor wang
 * @date 2018/11/18 11:10 AM
 * @description
 */
public interface TeacherRepository extends JpaRepository<Teacher, Integer> {

    // 使用 p0 做key
    @Cacheable(value = "teacherCache", key = "#p0")
    Teacher findByName(String name);

    // 使用自定义key生成器  二者公用一个userCache
    @Cacheable(value = "teacherCache", keyGenerator = "myKeyGenerator")
    Teacher findById(Long id);

    @Override
    @CachePut(value = "teacherCache", key = "#p0.name")
    Teacher save(Teacher user);

}
